﻿using System;

class CalculateTheSum
{
    static void Main()
    {
        //Write a program to calculate the sum (with accuracy of 0.001): 1 + 1/2 - 1/3 + 1/4 - 1/5 + ...

        double tempSum = 1;
        double newSum;
        double difference;
        double divider = 2;

        do
        {
            if (divider % 2 == 0)
            {
                newSum = tempSum + (1 / divider);
            }
            else
            {
                newSum = tempSum - (1 / divider);
            }
            difference = Math.Abs(newSum - tempSum);
            tempSum = newSum;
            divider++;
        }
        while (difference >= 0.001);

        Console.WriteLine("The answer is: " + newSum);
    }
}

